/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PanelFarmacologico.java
 *
 * Created on 20-sep-2010, 9:44:39
 */

package presentacion.tratamiento_medicamentoso;

import com.toedter.calendar.IDateEditor;
import hibernate.objeto.Farmacologico;
import hibernate.objeto.NombreComercialMedicamento;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Calendar;
import java.util.Date;
import java.util.Vector;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JSpinner;
import javax.swing.JSpinner.DefaultEditor;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SpinnerDateModel;
import logica.CapaLogica;
import logica.FarmacologicoLogica;
import logica.validacion.CapaValidacion;
import presentacion.CapaPresentacion;
import presentacion.acceso.RestriccionAcceso;
import presentacion.comun.ComunFarmacologicoPresentacion;
import presentacion.utilidad.maquetado.Fuente;
import presentacion.utilidad.maquetado.Icono;
import presentacion.utilidad.maquetado.InformeError;
import presentacion.medicamento.GestionMedicamentoPresentacion;
import presentacion.paciente.AntecedentePacientePresentacion;
import presentacion.utilidad.MensajePresentacion;

/**
 *
 * @author Administrador
 */
public class DatosFarmacologico extends javax.swing.JPanel {

    /** Creates new form DatosFarmacologico */
    /**
     * Constructor vacio para cuando se agregan farmacologicos.
     *
     * @param objeto
     * @param referenciaJDialogAntecedentePaciente
     * @param referenciaJDialogTratamientoMedicamentoso
     */
    public DatosFarmacologico(String objeto,
            AntecedentePacientePresentacion referenciaJDialogAntecedentePaciente,
            TratamientoMedicamentosoPresentacion referenciaJDialogTratamientoMedicamentoso) {
        initComponents();
        this.referenciaJDialogAntecedentePaciente =
                referenciaJDialogAntecedentePaciente;
        this.referenciaJDialogTratamientoMedicamentoso =
                referenciaJDialogTratamientoMedicamentoso;
        
        modoCarga(objeto); 
        
        setearEventosQueCapturanTeclaEnterYEscape();
    }

    /**
     * Setea la ventana en modo carga.
     * 
     */
    private void modoCarga(String objeto) {
        if (objeto.equalsIgnoreCase(
                TratamientoMedicamentosoPresentacion.class.getName())) {
            horaSpinnerFarmacologico.getModel().setValue(new Date());
            fechaFarmacologico.setDate(new Date());
        }

        botonAceptar.setVisible(false);
        botonFinalizarFarmacologico.setVisible(false);
    }

    /**
     * Constructor para visualizacion del objeto farmacologico.
     * 
     * @param owner
     * @param farmacologico
     * @param tabla
     * @param filtrar
     * @param vector
     * @param tablaActivo
     * @param filtrarActivo
     * @param vectorActivo
     */
    public DatosFarmacologico(JDialog owner, Farmacologico farmacologico,
            JTable tabla, JTextField filtrar, Vector<Farmacologico> vector,
            JTable tablaActivo, JTextField filtrarActivo,
            Vector<Farmacologico> vectorActivo) {
        initComponents();
        botonQuitarFarmacologico.setVisible(false);
        if (farmacologico.getEstadoFarmacologico().equalsIgnoreCase("No activo")) {
            botonFinalizarFarmacologico.setVisible(false);
        }

        this.owner = owner;
        this.farmacologico = farmacologico;
        this.tabla = tabla;
        this.filtrar = filtrar;
        this.vector = vector;
        this.tablaActivo = tablaActivo;
        this.filtrarActivo = filtrarActivo;
        this.vectorActivo = vectorActivo;

        if (CapaPresentacion.modoModificacion) {
            modoModificacion();
        } else if (CapaPresentacion.modoVisualizacion) {
            modoVisualizacion();
        }

        setearEventosQueCapturanTeclaEnterYEscape();
    }

    /**
     * Setea la ventana en modo modificación.
     *
     */
    private void modoModificacion() {
        exhibirDatosEnPantalla();

        horaSpinnerFarmacologico.getModel().setValue(new Date());
        fechaFarmacologico.setDate(new Date());

        if (!farmacologico.getEstadoFarmacologico().equalsIgnoreCase("Activo")) {
            modoVisualizacion();

        }
    }

    /**
     * Setea la ventana en modo visualizacion.
     *
     */
    private void modoVisualizacion() {
        exhibirDatosEnPantalla();
        setearEstadoCampos(false);
        botonAceptar.setText("Volver");
        botonAceptar.setToolTipText("Cancela la operación");
        botonAceptar.setIcon(Icono.ICONO_16_CANCELAR);
        botonAceptar.requestFocus();
    }

    /**
     * Exhibe los distintos datos cargados en la pantalla.
     *
     */
    private void exhibirDatosEnPantalla() {
        //Hora
        horaSpinnerFarmacologico.getModel().setValue(new Date(0, 0, 0,
                CapaLogica.separarHoras(farmacologico.getHoraFarmacologico()),
                CapaLogica.separarMinutos(farmacologico.getHoraFarmacologico()),
                CapaLogica.separarSegundos(farmacologico.getHoraFarmacologico())));

        //Fecha
        this.fechaFarmacologico.setDate(farmacologico.getFechaFarmacologico());

        //Medicamento
        this.medicamentoSeleccionado = farmacologico.getNombreComercialMedicamento();
        this.medicamentoFarmacologico.setText(
                farmacologico.getNombreComercialMedicamento().getNombreNombreComercialMedicamento());
        medicamentoFarmacologico.setToolTipText(medicamentoFarmacologico.getText());

        //Presentacion
        this.presentacionFarmacologico.setText(farmacologico.getNombreComercialMedicamento().
                getPresentacionesNombreComercialMedicamento());
        presentacionFarmacologico.setToolTipText(presentacionFarmacologico.getText());

        //Dosis
        this.dosisFarmacologico.setText(farmacologico.getDosisFarmacologico());
        dosisFarmacologico.setCaretPosition(0);

        //Intervalo
        this.intervaloFarmacologico.setText(farmacologico.getIntervaloFarmacologico());
        intervaloFarmacologico.setCaretPosition(0);

        //Duracion
        this.duracionFarmacologico.setText(farmacologico.getDuracionFarmacologico());
        duracionFarmacologico.setCaretPosition(0);

        //Efectivo
        if (farmacologico.getEfectivoFarmacologico().equals("si")) {
            efectivoSiFarmacologico.setSelected(true);
        } else if (farmacologico.getEfectivoFarmacologico().equals("no")) {
            efectivoNoFarmacologico.setSelected(true);
        }

        //Efecto Adverso
        if (farmacologico.getEfectoAdversoFarmacologico().equals("si")) {
            efectoAdversoSiFarmacologico.setSelected(true);
        } else if (farmacologico.getEfectoAdversoFarmacologico().equals("no")) {
            efectoAdversoNoFarmacologico.setSelected(true);
        }

        //Comentarios
        this.comentariosFarmacologico.setText(
                farmacologico.getComentariosFarmacologico());
        comentariosFarmacologico.setCaretPosition(0);
    }

    /**
     * Setea el estado de los campos.
     *
     * @param estado El estado a setear
     */
    private void setearEstadoCampos(boolean estado) {
        horaSpinnerFarmacologico.setEnabled(estado);
        fechaFarmacologico.setEnabled(estado);
        seleccionarFarmacologico.setEnabled(estado);
        dosisFarmacologico.setEnabled(estado);
        intervaloFarmacologico.setEnabled(estado);
        duracionFarmacologico.setEnabled(estado);
        efectivoNoFarmacologico.setEnabled(estado);
        efectivoSiFarmacologico.setEnabled(estado);
        efectoAdversoNoFarmacologico.setEnabled(estado);
        efectoAdversoSiFarmacologico.setEnabled(estado);
        comentariosFarmacologico.setEnabled(estado);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        textoHoraYFechaFarmacologico = new javax.swing.JLabel();
        SpinnerDateModel spinerModel = new SpinnerDateModel(new Date(0, 0, 0, 0, 0, 0), null, null, Calendar.HOUR_OF_DAY);
        horaSpinnerFarmacologico = new javax.swing.JSpinner(spinerModel);
        fechaFarmacologico = new com.toedter.calendar.JDateChooser();
        textoPresentacionFarmacologico = new javax.swing.JLabel();
        dosisFarmacologico = new javax.swing.JTextField();
        textoDosisFarmacologico = new javax.swing.JLabel();
        textoIntervaloFarmacologico = new javax.swing.JLabel();
        textoDuracionFarmacologico = new javax.swing.JLabel();
        textoEfectivoFarmacologico = new javax.swing.JLabel();
        textoEfectoAdversoFarmacologico = new javax.swing.JLabel();
        textoComentariosFarmacologico = new javax.swing.JLabel();
        duracionFarmacologico = new javax.swing.JTextField();
        intervaloFarmacologico = new javax.swing.JTextField();
        efectivoSiFarmacologico = new javax.swing.JRadioButton();
        efectivoNoFarmacologico = new javax.swing.JRadioButton();
        efectoAdversoSiFarmacologico = new javax.swing.JRadioButton();
        efectoAdversoNoFarmacologico = new javax.swing.JRadioButton();
        comentariosFarmacologicoScrollPane = new javax.swing.JScrollPane();
        comentariosFarmacologico = new javax.swing.JTextArea();
        botonQuitarFarmacologico = new javax.swing.JButton();
        seleccionarFarmacologico = new javax.swing.JButton();
        separadorFarmacologico = new javax.swing.JSeparator();
        botonAceptar = new javax.swing.JButton();
        botonFinalizarFarmacologico = new javax.swing.JButton();
        medicamentoFarmacologico = new javax.swing.JLabel();
        presentacionFarmacologico = new javax.swing.JLabel();

        setMaximumSize(new java.awt.Dimension(482, 354));
        setMinimumSize(new java.awt.Dimension(482, 354));

        textoHoraYFechaFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoHoraYFechaFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoHoraYFechaFarmacologico.setText("Hora y fecha");
        textoHoraYFechaFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));

        JSpinner.DateEditor horaDeMuerte = new JSpinner.DateEditor(horaSpinnerFarmacologico, "HH:mm:ss");
        horaSpinnerFarmacologico.setEditor(horaDeMuerte);
        horaSpinnerFarmacologico.setFont(Fuente.FUENTE_TEXTFIELD);
        horaSpinnerFarmacologico.setPreferredSize(new java.awt.Dimension(72, 20));

        fechaFarmacologico.setToolTipText("");
        fechaFarmacologico.setMaxSelectableDate(new Date());
        fechaFarmacologico.setMinSelectableDate(new java.util.Date(-2208985673000L));
        fechaFarmacologico.setPreferredSize(new java.awt.Dimension(114, 20));

        textoPresentacionFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoPresentacionFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoPresentacionFarmacologico.setText("Presentación");
        textoPresentacionFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));

        dosisFarmacologico.setFont(Fuente.FUENTE_TEXTFIELD);
        dosisFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        dosisFarmacologico.setPreferredSize(new java.awt.Dimension(190, 20));

        textoDosisFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoDosisFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoDosisFarmacologico.setText("Dosis");
        textoDosisFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));

        textoIntervaloFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoIntervaloFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoIntervaloFarmacologico.setText("Intervalo");
        textoIntervaloFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));

        textoDuracionFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoDuracionFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoDuracionFarmacologico.setText("Duración");
        textoDuracionFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));

        textoEfectivoFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoEfectivoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoEfectivoFarmacologico.setText("Efectivo");
        textoEfectivoFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));

        textoEfectoAdversoFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoEfectoAdversoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoEfectoAdversoFarmacologico.setText("Efecto adveso");
        textoEfectoAdversoFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));

        textoComentariosFarmacologico.setFont(Fuente.FUENTE_LABEL);
        textoComentariosFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        textoComentariosFarmacologico.setText("Comentarios");
        textoComentariosFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));

        duracionFarmacologico.setFont(Fuente.FUENTE_TEXTFIELD);
        duracionFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        duracionFarmacologico.setPreferredSize(new java.awt.Dimension(190, 20));

        intervaloFarmacologico.setFont(Fuente.FUENTE_TEXTFIELD);
        intervaloFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        intervaloFarmacologico.setPreferredSize(new java.awt.Dimension(190, 20));

        efectivoSiFarmacologico.setFont(Fuente.FUENTE_RADIOBUTTON);
        efectivoSiFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        efectivoSiFarmacologico.setText("si");
        efectivoSiFarmacologico.setPreferredSize(new java.awt.Dimension(75, 14));
        efectivoSiFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                efectivoSiFarmacologicoActionPerformed(evt);
            }
        });

        efectivoNoFarmacologico.setFont(Fuente.FUENTE_RADIOBUTTON);
        efectivoNoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        efectivoNoFarmacologico.setText("no");
        efectivoNoFarmacologico.setPreferredSize(new java.awt.Dimension(75, 14));
        efectivoNoFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                efectivoNoFarmacologicoActionPerformed(evt);
            }
        });

        efectoAdversoSiFarmacologico.setFont(Fuente.FUENTE_RADIOBUTTON);
        efectoAdversoSiFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        efectoAdversoSiFarmacologico.setText("si");
        efectoAdversoSiFarmacologico.setPreferredSize(new java.awt.Dimension(75, 14));
        efectoAdversoSiFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                efectoAdversoSiFarmacologicoActionPerformed(evt);
            }
        });

        efectoAdversoNoFarmacologico.setFont(Fuente.FUENTE_RADIOBUTTON);
        efectoAdversoNoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        efectoAdversoNoFarmacologico.setText("no");
        efectoAdversoNoFarmacologico.setPreferredSize(new java.awt.Dimension(75, 14));
        efectoAdversoNoFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                efectoAdversoNoFarmacologicoActionPerformed(evt);
            }
        });

        comentariosFarmacologicoScrollPane.setForeground(Fuente.COLOR_NORMAL);
        comentariosFarmacologicoScrollPane.setPreferredSize(new java.awt.Dimension(166, 40));

        comentariosFarmacologico.setColumns(20);
        comentariosFarmacologico.setFont(Fuente.FUENTE_TEXTFIELD);
        comentariosFarmacologico.setLineWrap(true);
        comentariosFarmacologico.setRows(1);
        comentariosFarmacologico.setWrapStyleWord(true);
        comentariosFarmacologicoScrollPane.setViewportView(comentariosFarmacologico);

        botonQuitarFarmacologico.setFont(Fuente.FUENTE_BOTON_INTERNO);
        botonQuitarFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        botonQuitarFarmacologico.setIcon(Icono.ICONO_16_QUITAR);
        botonQuitarFarmacologico.setMnemonic('q');
        botonQuitarFarmacologico.setText("Quitar medicamento");
        botonQuitarFarmacologico.setToolTipText("Remueve este conjunto de datos");
        botonQuitarFarmacologico.setPreferredSize(new java.awt.Dimension(150, 20));
        botonQuitarFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonQuitarFarmacologicoActionPerformed(evt);
            }
        });

        seleccionarFarmacologico.setFont(Fuente.FUENTE_BOTON_INTERNO);
        seleccionarFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        seleccionarFarmacologico.setMnemonic('m');
        seleccionarFarmacologico.setText("Medicamento");
        seleccionarFarmacologico.setToolTipText("Seleccione el medicamento asociado");
        seleccionarFarmacologico.setPreferredSize(new java.awt.Dimension(95, 20));
        seleccionarFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                seleccionarFarmacologicoActionPerformed(evt);
            }
        });

        separadorFarmacologico.setPreferredSize(new java.awt.Dimension(290, 2));

        botonAceptar.setFont(Fuente.FUENTE_BOTON_INTERNO);
        botonAceptar.setForeground(Fuente.COLOR_NORMAL);
        botonAceptar.setIcon(Icono.ICONO_16_ACEPTAR);
        botonAceptar.setMnemonic('a');
        botonAceptar.setText("Aceptar");
        botonAceptar.setToolTipText("Modifica el farmacologico");
        botonAceptar.setPreferredSize(new java.awt.Dimension(150, 20));
        botonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonAceptarActionPerformed(evt);
            }
        });

        botonFinalizarFarmacologico.setFont(Fuente.FUENTE_BOTON_INTERNO);
        botonFinalizarFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        botonFinalizarFarmacologico.setIcon(Icono.ICONO_16_ACEPTAR);
        botonFinalizarFarmacologico.setMnemonic('f');
        botonFinalizarFarmacologico.setText("Finalizar");
        botonFinalizarFarmacologico.setToolTipText("Finaliza el tratamiento de este medicamento");
        botonFinalizarFarmacologico.setPreferredSize(new java.awt.Dimension(150, 20));
        botonFinalizarFarmacologico.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonFinalizarFarmacologicoActionPerformed(evt);
            }
        });

        medicamentoFarmacologico.setFont(Fuente.FUENTE_LABEL);
        medicamentoFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        medicamentoFarmacologico.setPreferredSize(new java.awt.Dimension(190, 20));

        presentacionFarmacologico.setFont(Fuente.FUENTE_LABEL);
        presentacionFarmacologico.setForeground(Fuente.COLOR_NORMAL);
        presentacionFarmacologico.setPreferredSize(new java.awt.Dimension(190, 20));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(separadorFarmacologico, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(textoIntervaloFarmacologico, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoDosisFarmacologico, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoDuracionFarmacologico, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoEfectivoFarmacologico, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textoEfectoAdversoFarmacologico, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(seleccionarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textoPresentacionFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textoHoraYFechaFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textoComentariosFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(presentacionFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(comentariosFarmacologicoScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(horaSpinnerFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(fechaFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(dosisFarmacologico, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(intervaloFarmacologico, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(duracionFarmacologico, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(efectivoSiFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(efectivoNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(efectoAdversoSiFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(efectoAdversoNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(medicamentoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                        .addComponent(botonQuitarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botonFinalizarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(textoHoraYFechaFarmacologico, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(horaSpinnerFarmacologico, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(fechaFarmacologico, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(seleccionarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(medicamentoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(textoPresentacionFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(presentacionFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoDosisFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dosisFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoIntervaloFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(intervaloFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoDuracionFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(duracionFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoEfectivoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(efectivoSiFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(efectivoNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textoEfectoAdversoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(efectoAdversoSiFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(efectoAdversoNoFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(textoComentariosFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comentariosFarmacologicoScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(13, 13, 13)
                .addComponent(separadorFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonQuitarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonFinalizarFarmacologico, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botonAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(14, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void botonQuitarFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonQuitarFarmacologicoActionPerformed
        JPanel panelPadre = (JPanel) botonQuitarFarmacologico.getParent().getParent();

        panelPadre.remove(botonQuitarFarmacologico.getParent());
        panelPadre.revalidate();
        panelPadre.repaint();
    }//GEN-LAST:event_botonQuitarFarmacologicoActionPerformed

    private void efectoAdversoSiFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_efectoAdversoSiFarmacologicoActionPerformed
        if (efectoAdversoSiFarmacologico.isSelected()) {
            efectoAdversoNoFarmacologico.setSelected(false);
        }
}//GEN-LAST:event_efectoAdversoSiFarmacologicoActionPerformed

    private void efectoAdversoNoFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_efectoAdversoNoFarmacologicoActionPerformed
        if (efectoAdversoNoFarmacologico.isSelected()) {
            efectoAdversoSiFarmacologico.setSelected(false);
        }
}//GEN-LAST:event_efectoAdversoNoFarmacologicoActionPerformed

    private void efectivoNoFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_efectivoNoFarmacologicoActionPerformed
        if (efectivoNoFarmacologico.isSelected()) {
            efectivoSiFarmacologico.setSelected(false);
        }
}//GEN-LAST:event_efectivoNoFarmacologicoActionPerformed

    private void efectivoSiFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_efectivoSiFarmacologicoActionPerformed
        if (efectivoSiFarmacologico.isSelected()) {
            efectivoNoFarmacologico.setSelected(false);
        }
}//GEN-LAST:event_efectivoSiFarmacologicoActionPerformed

    private void seleccionarFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_seleccionarFarmacologicoActionPerformed
        RestriccionAcceso.GestionMedicamentoPresentacion(null, true, false);

        //Completa el campo con el medicamento seleccionado
        NombreComercialMedicamento medicamentoSeleccionadoDeTabla =
                GestionMedicamentoPresentacion.getNombreComercialSeleccionado();

        //Setea la enfermedad seleccionada
        medicamentoSeleccionado = medicamentoSeleccionadoDeTabla;
        if(medicamentoSeleccionadoDeTabla != null){
            medicamentoFarmacologico.setText(medicamentoSeleccionadoDeTabla.
                    getNombreNombreComercialMedicamento());
            presentacionFarmacologico.setText(medicamentoSeleccionadoDeTabla.
                    getPresentacionesNombreComercialMedicamento());
        }
        medicamentoFarmacologico.setToolTipText(
                medicamentoFarmacologico.getText());
        presentacionFarmacologico.setToolTipText(
                presentacionFarmacologico.getText());
}//GEN-LAST:event_seleccionarFarmacologicoActionPerformed

    private void botonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonAceptarActionPerformed
        if (farmacologico.getEstadoFarmacologico().equalsIgnoreCase("Activo")) {
            modificarFarmacologico();
        } else {
            cerrarGUI();
        }
    }//GEN-LAST:event_botonAceptarActionPerformed

    private void botonFinalizarFarmacologicoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonFinalizarFarmacologicoActionPerformed
        new ComunFarmacologicoPresentacion(
                owner, farmacologico, tabla, tablaActivo, filtrar,
                filtrarActivo, vector, vectorActivo).finalizarFarmacologico();

        cerrarGUI();
}//GEN-LAST:event_botonFinalizarFarmacologicoActionPerformed

    /**
     * Modifica el objeto farmacologico.
     * 
     */
    private void modificarFarmacologico() {
        //Valida todos los datos ingresados
        if (validarCamposLocal()) {
            //Carga toda la información de la pantalla
            recopilarInformacionFarmacologico();

            if (FarmacologicoLogica.modificarFarmacologico(
                    datosFarmacologico, farmacologico)) {
                cerrarGUI();
            }

        } else {
            MensajePresentacion.errorDatosInvalidos();
        }
    }

    /**
     * Valida en conjunto todos los campos. Aquellos que son obligatorios y los
     * que no. Uso local
     *
     * @return true si el objeto está listo para cargarse, false en caso
     * contrario
     */
    public boolean validarCamposLocal() {
        boolean esFechaValida = false;
        boolean esMedicamentoValida = false;
        boolean esDosisValida = false;
        boolean esIntervaloValida = false;

        if (!CapaValidacion.validarFecha(
                fechaFarmacologico.getDate(), "", true)) {
            textoHoraYFechaFarmacologico.setForeground(
                    Fuente.COLOR_ERROR);
            textoHoraYFechaFarmacologico.setToolTipText(InformeError.
                    INFORME_ERROR_USO_COMUN_HORA_Y_FECHA);
            esFechaValida = false;
        } else {
            textoHoraYFechaFarmacologico.setForeground(Fuente.COLOR_NORMAL);
            textoHoraYFechaFarmacologico.setToolTipText(null);
            esFechaValida = true;
        }

        if (!CapaValidacion.validarCampoObligatorio(
                medicamentoFarmacologico.getText())) {
            seleccionarFarmacologico.setForeground(
                    Fuente.COLOR_ERROR);
            medicamentoFarmacologico.setToolTipText(InformeError.
                    INFORME_ERROR_MEDICAMENTO_NOMBRE_COMERCIAL_SELECCION_BOTON);
            esMedicamentoValida = false;
        } else {
            seleccionarFarmacologico.setForeground(Fuente.COLOR_NORMAL);
            esMedicamentoValida = true;
            medicamentoFarmacologico.setToolTipText(null);
        }
        if (!CapaValidacion.validarCampoObligatorio(
                dosisFarmacologico.getText())) {
            textoDosisFarmacologico.setForeground(
                    Fuente.COLOR_ERROR);
            textoDosisFarmacologico.setToolTipText(InformeError.
                    INFORME_ERROR_DATOS_FARMACOLOGICO_DOSIS);
            esDosisValida = false;
        } else {
            textoDosisFarmacologico.setForeground(Fuente.COLOR_NORMAL);
            textoDosisFarmacologico.setToolTipText(null);
            esDosisValida = true;
        }

        if (!CapaValidacion.validarCampoObligatorio(
                intervaloFarmacologico.getText())) {
            textoIntervaloFarmacologico.setForeground(
                    Fuente.COLOR_ERROR);
            textoIntervaloFarmacologico.setToolTipText(InformeError.
                    INFORME_ERROR_DATOS_FARMACOLOGICO_INTERVALO);
            esIntervaloValida = false;
        } else {
            textoIntervaloFarmacologico.setForeground(Fuente.COLOR_NORMAL);
            textoIntervaloFarmacologico.setToolTipText(null);
            esIntervaloValida = true;
        }

        return esFechaValida && esMedicamentoValida && esDosisValida &&
                esIntervaloValida;
    }

    /**
     * Valida en conjunto todos los campos. Aquellos que son obligatorios y los
     * que no. Se utiliza desde tratamientos
     *
     * @return true si el objeto está listo para cargarse, false en caso
     * contrario
     */
    public boolean validarCampos() {
        JTabbedPane panelTabs  = ((JTabbedPane) this.getParent().getParent().
                getParent().getParent().getParent());
        int indice = 0;
        for (int i = 0; i < panelTabs.getTabCount(); i++) {
            if (panelTabs.getTitleAt(i).equalsIgnoreCase("farmacológico")) {
                indice = 0;
            }
        }

        boolean esFechaValida = validarCampoFecha(indice, panelTabs);
        boolean esMedicamentoValida = validarCampoMedicamento(indice, panelTabs);
        boolean esDosisValida = validarCampoDosis(indice, panelTabs);
        boolean esIntervaloValida = validarCampoIntervalo(indice, panelTabs);

        return (esFechaValida && esMedicamentoValida &&
                esDosisValida && esIntervaloValida);
    }

    /**
     * Valida los campos correspondiente al campo fecha.
     *
     * @param indice El indice de la solapa a pintar en caso de error
     * @param panelTabs Las solapas que contienen los paneles
     * @return true si los campos estan listos para cargarse, false en caso
     * contrario
     */
    private boolean validarCampoFecha(int indice, JTabbedPane panelTabs) {
        
        boolean retorno;
        
        if (!CapaValidacion.validarFecha(
                fechaFarmacologico.getDate(), "", true)) {
            textoHoraYFechaFarmacologico.setForeground(
                    Fuente.COLOR_ERROR);
            textoHoraYFechaFarmacologico.setToolTipText(InformeError.
                    INFORME_ERROR_USO_COMUN_HORA_Y_FECHA);
            panelTabs.setForegroundAt(indice, Fuente.COLOR_ERROR);
            retorno = false;
        } else {
            textoHoraYFechaFarmacologico.setForeground(Fuente.COLOR_NORMAL);
            panelTabs.setForegroundAt(indice, Fuente.COLOR_ERROR);
            textoHoraYFechaFarmacologico.setToolTipText(null);
            retorno = true;
        }

        return retorno;
    }

    /**
     * Valida los campos correspondiente al campo dosis.
     *
     * @param indice El indice de la solapa a pintar en caso de error
     * @param panelTabs Las solapas que contienen los paneles
     * @return true si los campos estan listos para cargarse, false en caso
     * contrario
     */
    private boolean validarCampoMedicamento(int indice, JTabbedPane panelTabs) {
        boolean retorno;

        if (!CapaValidacion.validarCampoObligatorio(
                medicamentoFarmacologico.getText())) {
            seleccionarFarmacologico.setForeground(
                    Fuente.COLOR_ERROR);
            panelTabs.setForegroundAt(indice, Fuente.COLOR_ERROR);
            medicamentoFarmacologico.setToolTipText(InformeError.
                    INFORME_ERROR_MEDICAMENTO_NOMBRE_COMERCIAL_SELECCION_BOTON);
            retorno = false;
        } else {
            seleccionarFarmacologico.setForeground(Fuente.COLOR_NORMAL);
            panelTabs.setForegroundAt(indice, Fuente.COLOR_NORMAL);
            retorno = true;
            medicamentoFarmacologico.setToolTipText(null);
        }

        return retorno;
    }

    /**
     * Valida los campos correspondiente al campo dosis.
     *
     * @param indice El indice de la solapa a pintar en caso de error
     * @param panelTabs Las solapas que contienen los paneles
     * @return true si los campos estan listos para cargarse, false en caso
     * contrario
     */
    private boolean validarCampoDosis(int indice, JTabbedPane panelTabs) {
        boolean retorno;

        if (!CapaValidacion.validarCampoObligatorio(
                dosisFarmacologico.getText())) {
            textoDosisFarmacologico.setForeground(
                    Fuente.COLOR_ERROR);
            textoDosisFarmacologico.setToolTipText(InformeError.
                    INFORME_ERROR_DATOS_FARMACOLOGICO_DOSIS);
            panelTabs.setForegroundAt(indice, Fuente.COLOR_ERROR);
            retorno = false;
        } else {
            textoDosisFarmacologico.setForeground(Fuente.COLOR_NORMAL);
            panelTabs.setForegroundAt(indice, Fuente.COLOR_NORMAL);
            textoDosisFarmacologico.setToolTipText(null);
            retorno = true;
        }

        return retorno;
    }

    /**
     * Valida los campos correspondiente al campo intervalo.
     *
     * @param indice El indice de la solapa a pintar en caso de error
     * @param panelTabs Las solapas que contienen los paneles
     * @return true si los campos estan listos para cargarse, false en caso
     * contrario
     */
    private boolean validarCampoIntervalo(int indice, JTabbedPane panelTabs) {
        boolean retorno;

        if (!CapaValidacion.validarCampoObligatorio(
                intervaloFarmacologico.getText())) {
            textoIntervaloFarmacologico.setForeground(
                    Fuente.COLOR_ERROR);
            textoIntervaloFarmacologico.setToolTipText(InformeError.
                    INFORME_ERROR_DATOS_FARMACOLOGICO_INTERVALO);
            panelTabs.setForegroundAt(indice, Fuente.COLOR_ERROR);
            retorno = false;
        } else {
            textoIntervaloFarmacologico.setForeground(Fuente.COLOR_NORMAL);
            panelTabs.setForegroundAt(indice, Fuente.COLOR_NORMAL);
            textoIntervaloFarmacologico.setToolTipText(null);
            retorno = true;
        }

        return retorno;
    }

    /**
     * Recopila toda la informacion ingresada en el panel de Farmacologico.
     *
     */
    private void recopilarInformacionFarmacologico() {
        datosFarmacologico = new Object[10];

        datosFarmacologico[CapaLogica.FARMACOLOGICO_HORA] =
                getHoraFarmacologico();

        datosFarmacologico[CapaLogica.FARMACOLOGICO_FECHA] =
                getFechaFarmacologico();

        datosFarmacologico[CapaLogica.FARMACOLOGICO_NOMBRE_COMERCIAL_MEDICAMENTO] =
                getMedicamentoSeleccionado();

        datosFarmacologico[CapaLogica.FARMACOLOGICO_DOSIS] =
                getDosisFarmacologico();

        datosFarmacologico[CapaLogica.FARMACOLOGICO_INTERVALO] =
                getIntervaloFarmacologico();

        datosFarmacologico[CapaLogica.FARMACOLOGICO_DURACION] =
                getDuracionFarmacologico();

        if (getEfectivoSiFarmacologico()) {
            datosFarmacologico[CapaLogica.FARMACOLOGICO_EFECTIVO] = "si";
        } else if (getEfectivoNoFarmacologico()) {
            datosFarmacologico[CapaLogica.FARMACOLOGICO_EFECTIVO] = "no";
        } else {
            datosFarmacologico[CapaLogica.FARMACOLOGICO_EFECTIVO] = "";
        }

        if (getEfectoAdversoSiFarmacologico()) {
            datosFarmacologico[CapaLogica.FARMACOLOGICO_EFECTO_ADVERSO] = "si";
        } else if (getEfectoAdversoNoFarmacologico()) {
            datosFarmacologico[CapaLogica.FARMACOLOGICO_EFECTO_ADVERSO] = "no";
        } else {
            datosFarmacologico[CapaLogica.FARMACOLOGICO_EFECTO_ADVERSO] = "";
        }

        datosFarmacologico[CapaLogica.FARMACOLOGICO_COMENTARIOS] =
                getComentariosFarmacologico();

        datosFarmacologico[CapaLogica.FARMACOLOGICO_ESTADO] = "Activo";
    }

    /**
     * Cierra el JDialog que contiene al panel.
     */
    private void cerrarGUI() {
        JDialog jdialog = (JDialog)
                this.getParent().getParent().getParent().getParent();
        jdialog.dispose();
    }
    
    public String getComentariosFarmacologico() {
        return comentariosFarmacologico.getText();
    }

    public String getDosisFarmacologico() {
        return dosisFarmacologico.getText();
    }

    public String getDuracionFarmacologico() {
        return duracionFarmacologico.getText();
    }

    public boolean getEfectivoNoFarmacologico() {
        return efectivoNoFarmacologico.isSelected();
    }

    public boolean getEfectivoSiFarmacologico() {
        return efectivoSiFarmacologico.isSelected();
    }

    public boolean getEfectoAdversoNoFarmacologico() {
        return efectoAdversoNoFarmacologico.isSelected();
    }

    public boolean getEfectoAdversoSiFarmacologico() {
        return efectoAdversoSiFarmacologico.isSelected();
    }

    public Date getFechaFarmacologico() {
        return fechaFarmacologico.getDate();
    }

    public String getHoraFarmacologico() {
        return CapaLogica.separarTiempo(
                horaSpinnerFarmacologico.getModel().getValue().toString());
    }

    public String getIntervaloFarmacologico() {
        return intervaloFarmacologico.getText();
    }

    public NombreComercialMedicamento getMedicamentoSeleccionado() {
        return medicamentoSeleccionado;
    }

    /**
     * Setea en cada componente del JDialog los eventos que capturarán la tecla
     * enter y escape.
     */
    private void setearEventosQueCapturanTeclaEnterYEscape() {
        //Declaración del evento a capturar
        KeyListener keyListenerEscape = new KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
                    //Llamada al método que capturará el boton enter y
                    //trabajará sobre el mismo
                    if (referenciaJDialogAntecedentePaciente != null) {
                    referenciaJDialogAntecedentePaciente.dispose();
                    } else if (referenciaJDialogTratamientoMedicamentoso != null){
                        referenciaJDialogTratamientoMedicamentoso.dispose();
                    } else {
                        cerrarGUI();
                    }
                }
            }
        };
        //Setear eventos
        ((DefaultEditor) horaSpinnerFarmacologico.getEditor()).
                getTextField().addKeyListener(keyListenerEscape);

        ((IDateEditor) fechaFarmacologico.getDateEditor()).
                getUiComponent().addKeyListener(keyListenerEscape);
        dosisFarmacologico.addKeyListener(keyListenerEscape);
        intervaloFarmacologico.addKeyListener(keyListenerEscape);
        duracionFarmacologico.addKeyListener(keyListenerEscape);
        efectivoNoFarmacologico.addKeyListener(keyListenerEscape);
        efectivoSiFarmacologico.addKeyListener(keyListenerEscape);
        efectoAdversoNoFarmacologico.addKeyListener(keyListenerEscape);
        efectoAdversoSiFarmacologico.addKeyListener(keyListenerEscape);
        comentariosFarmacologico.addKeyListener(keyListenerEscape);
        botonQuitarFarmacologico.addKeyListener(keyListenerEscape);
        botonAceptar.addKeyListener(keyListenerEscape);
        botonFinalizarFarmacologico.addKeyListener(keyListenerEscape);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JButton botonFinalizarFarmacologico;
    private javax.swing.JButton botonQuitarFarmacologico;
    private javax.swing.JTextArea comentariosFarmacologico;
    private javax.swing.JScrollPane comentariosFarmacologicoScrollPane;
    private javax.swing.JTextField dosisFarmacologico;
    private javax.swing.JTextField duracionFarmacologico;
    private javax.swing.JRadioButton efectivoNoFarmacologico;
    private javax.swing.JRadioButton efectivoSiFarmacologico;
    private javax.swing.JRadioButton efectoAdversoNoFarmacologico;
    private javax.swing.JRadioButton efectoAdversoSiFarmacologico;
    private com.toedter.calendar.JDateChooser fechaFarmacologico;
    private javax.swing.JSpinner horaSpinnerFarmacologico;
    private javax.swing.JTextField intervaloFarmacologico;
    private javax.swing.JLabel medicamentoFarmacologico;
    private javax.swing.JLabel presentacionFarmacologico;
    private javax.swing.JButton seleccionarFarmacologico;
    private javax.swing.JSeparator separadorFarmacologico;
    private javax.swing.JLabel textoComentariosFarmacologico;
    private javax.swing.JLabel textoDosisFarmacologico;
    private javax.swing.JLabel textoDuracionFarmacologico;
    private javax.swing.JLabel textoEfectivoFarmacologico;
    private javax.swing.JLabel textoEfectoAdversoFarmacologico;
    private javax.swing.JLabel textoHoraYFechaFarmacologico;
    private javax.swing.JLabel textoIntervaloFarmacologico;
    private javax.swing.JLabel textoPresentacionFarmacologico;
    // End of variables declaration//GEN-END:variables
    private NombreComercialMedicamento medicamentoSeleccionado;
    private Farmacologico farmacologico;
    private JDialog owner;
    private JTable tabla;
    private JTable tablaActivo;
    private JTextField filtrar;
    private JTextField filtrarActivo;
    private Vector<Farmacologico> vector;
    private Vector<Farmacologico> vectorActivo;
    private AntecedentePacientePresentacion referenciaJDialogAntecedentePaciente;
    private TratamientoMedicamentosoPresentacion referenciaJDialogTratamientoMedicamentoso;
    private Object[] datosFarmacologico;
}